﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Design;
using System.Web.UI.HtmlControls;
using System.Collections.ObjectModel;
using System.ComponentModel.Design;


[assembly: WebResource("WebComponents.Templates.AdminControlProj.Css.Main.css", "text/css")]
[assembly: WebResource("WebComponents.Templates.AdminControlProj.Css.Simple.css", "text/css")]
namespace WebComponents.Templates.AdminControlProj
{
    [
    Designer(typeof(ACPPageDesigner)),
    DefaultProperty("Title"),
    ToolboxData("<{0}:ACPPage runat=\"server\"> </{0}:ACPPage>"),
    ]
    [ToolboxBitmap(typeof(ACPPage), "WebComponents.Templates.AdminControlProj.Images.ACPPage.bmp")]
    public class ACPPage : CompositeControl
    {
        #region Private Member Variables
        private string title;
        private ITemplate content;
        private ACPPageContent contentValue;
        private ACPPageIType type;
        private string cssFolder;
        #endregion

        #region Properties
        /// <summary>
        /// 
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        Description("Title Of Page"),
        ]
        public virtual string Title
        {
            get
            {
                return title;
            }
            set
            {
                title = value;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(ACPPageIType.Main),
        Description("Type of ACPPage"),
        ]
        public virtual ACPPageIType Type
        {
            get
            {
                return type;
            }
            set
            {
                type = value;
            }
        }
        /// <summary>
        /// 
        /// </summary>

        [
        Browsable(false),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        ]
        public ACPPageContent ContentValue
        {
            get
            {
                return contentValue;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        [
        Browsable(false),
        PersistenceMode(PersistenceMode.InnerDefaultProperty),
        TemplateInstance(TemplateInstance.Single),
        DefaultValue(null),
        Description("Control Content"),
        TemplateContainer(typeof(ACPPage)),
        ]
        public virtual ITemplate Content
        {
            get
            {
                return content;
            }
            set
            {
                content = value;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        Description("Folder contains css files"),
        ]
        public virtual string CssFolder
        {
            get
            {
                return cssFolder;
            }
            set
            {
                cssFolder = value;
            }
        }

        #endregion

        protected override void CreateChildControls()
        {
            Controls.Clear();

            #region content
            this.contentValue = new ACPPageContent();

            ITemplate _content = content;
            if (_content == null)
            {
                _content = new ACPPageTemplate();
            }
            _content.InstantiateIn(this.contentValue);

            this.Controls.Add(this.contentValue);
            #endregion


        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            contentValue = new ACPPageContent();
            ITemplate _content = content;
            if (_content == null)
            {
                _content = new ACPPageTemplate();
            }
            _content.InstantiateIn(contentValue);

            writer.Write(String.Format("<!--[if lt IE 9]><div class='ie'><![endif]-->"));
            writer.Write(String.Format("<!--[if lt IE 8]><div class='ie7'><![endif]-->"));

            #region Header
            writer.Write(String.Format("<header>"));
            #region Server Status
            writer.Write(String.Format("<div class='container_12'>"));
            writer.Write(String.Format("<p id='skin-name'><small>Constellation<br> Admin Skin</small> <strong>1.0</strong></p>"));
            writer.Write(String.Format("<div class='server-info'>Server: <strong>Apache (unknown)</strong></div>"));
            writer.Write(String.Format("<div class='server-info'>Php: <strong>5.2.17</strong></div>"));
            writer.Write(String.Format(""));
            writer.Write(String.Format("</div>"));
            #endregion
            #region Main Navigation
            writer.Write(String.Format("<nav id='main-nav'>"));
            writer.Write(String.Format("<ul class='container_12'>"));
            // Menu Level 1 [Home]
            writer.Write(String.Format("<li class='home current'><a href='javascript:void(0)' title='Home'>Home</a></li>"));
            // Menu Level 1 [Write]
            writer.Write(String.Format("<li class='write'><a href='javascript:void(0)' title='Home'>Write</a>"));
            // Menu Level 2 [Write] [Articles]
            writer.Write(String.Format("<ul>"));
            writer.Write(String.Format("<li><a href='javascript:void(0)' title='Articles'>Articles</a></li>"));
            writer.Write(String.Format("<li><a href='javascript:void(0)' title='Posts'>Posts</a></li>"));
            writer.Write(String.Format("</li>"));


            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format("</ul>"));
            writer.Write(String.Format("</nav>"));
            #endregion
            #region Sub Navigation
            writer.Write(String.Format("<div id='sub-nav'>"));
            writer.Write(String.Format("<div class='container_12'>"));
            writer.Write(String.Format("<a href='javascript:void(0)' title='Help' class='nav-button'><b>Help</b></a>"));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format("</div>"));
            writer.Write(String.Format("</div>"));
            #endregion
            writer.Write(String.Format("</header>"));
            #endregion

            #region Content
            this.contentValue.RenderControl(writer);
            #endregion

            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format(""));
            writer.Write(String.Format("<!--[if lt IE 8]></div><![endif]-->"));
            writer.Write(String.Format("<!--[if lt IE 9]></div><![endif]-->"));           
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Page.Header.Title = this.Type.ToString();

            #region Generate Css
            if (this.CssFolder != string.Empty)
            {
                HtmlLink link = new HtmlLink();
                link.Attributes.Add("href", this.Page.ClientScript.GetWebResourceUrl(this.GetType(), String.Format("WebComponents.Templates.AdminControlProj.Css.{0}.css", this.Type.ToString())));
                link.Attributes.Add("type", "text/css");
                link.Attributes.Add("rel", "stylesheet");
               this.Page.Header.Controls.AddAt(1, link);
   
            }
             #endregion
      
            string[] metaTags = "charset`utf-8|description`WebComponents ( v2.0 )".Split('|');
            foreach (string metaTag in metaTags)
            {
                HtmlMeta meta = new HtmlMeta();
                int index = 0;
                foreach (string tag in metaTag.Split('`'))
                {
                    index++;
                    if (index == 1)
                        meta.Name = tag;
                    if (index == 2)
                        meta.Content = tag;
                   
                }
                this.Page.Header.Controls.Add(meta);
            }
        }
    }

    
    [ToolboxItem(false)]
    public class ACPPageContent : WebControl
    {
    }

}


